import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  OneToMany,
  ManyToOne,
} from 'typeorm';
import { Role } from './role';
import { Article } from './article';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  username: string;

  @Column({ select: false })
  password: string;

  @Column({ nullable: true })
  email: string;

  @Column({ nullable: true })
  avatar: string;

  @Column()
  grade: number;

  @ManyToOne(() => Role, role => role.users) // note: we will create author property in the Photo class below
  role: Role;

  @OneToMany(() => Article, article => article.user) // note: we will create author property in the Photo class below
  articles: Article[];

  @CreateDateColumn()
  createDate;

  @UpdateDateColumn()
  updateDate;

  @DeleteDateColumn()
  deleteDate;
}
